package com.qiangzhi.valid;

import com.qiangzhi.annotation.Account;
import com.qiangzhi.constant.RegexConstant;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Account注解具体校验逻辑的实现类
 */
public class AccountValid implements ConstraintValidator<Account, Long> {

    @Override
    public boolean isValid(Long account, ConstraintValidatorContext constraintValidatorContext) {
        String value = String.valueOf(account); // 需要先将Long转为String才能进行正则校验
        return value.matches(RegexConstant.ACCOUNT_REGEX); // 正则校验
    }

}
